// 集中分类管理项目中所有的异步请求方法
// 为了后期项目维护考虑
// 方便异步请求的复用
// 为了看懂别人的代码

import request from "@/utils/request";
// 发布分类
export const categoryPost = (cateObj) => {
  return request.post("classes/VueCategory", cateObj);
  // return undefined
};

// categoryPost().then()

// 加载所有分类
// export const categoryGet = () => {
//   return request.get("classes/VueCategory");
// };

// 加载指定分类
//[all为true,加载所有数据]
//[all为false/undefined,加载主类目数据]
export const categoryGet = (all) => {
  let where = all ? {} : { parentId: "0-0" };
  return request.get("classes/VueCategory", {
    params: {
      where,
    },
  });
};

//企业入驻
export const companyPost = (company) => {
  return request.post("classes/VueCompany", company);
};

//岗位列表
export const jobGet = (page = 1, name, category) => {
  let skip = (page - 1) * 10;
  let where = {};
  if (name && name.trim()) {
    // where.jobName = name; //绝对匹配
    where.jobName = { $regex: name, $options: "i" }; //正则匹配、模糊查询
  }
  if (category) {
    where.lv1 = category;
  }
  return request.get("classes/VueJob", {
    params: {
      limit: 10,
      count: 1, //开启计数
      skip,
      where,
    },
  });
};

//图表
export const pieGet = () => {
  return request.get("classes/VueChart");
};
